﻿@model Lottery.Models.Home.UserListModel
@{
    ViewBag.Title = "会员系统 - 用户列表";
    Model.Caption = "用户列表";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
<div class="system_toolbar">
    <input type="button" id="btnNew" value="新增" />
    <input type="button" id="btnModify" value="重置密码" />
    <input type="button" id="btnStop" value="停用/启用" />
</div>  
@{
    System.Text.StringBuilder sb = new System.Text.StringBuilder();
    sb.AppendLine(string.Format("var data={{Total:{0},", Model.List.Count));
    sb.AppendLine("Rows:[");
    for (int i = 0; i < Model.List.Count; i++)
    {
        var item = Model.List[i];
        if(i == 0)
        {
            sb.Append("{");
        }
        else
        {
            sb.Append(",{");
        }
        sb.Append(string.Format("ID:'{0}',", item.Id));
        sb.Append(string.Format("Name:'{0}',", item.Name));
        sb.Append(string.Format("CreateDate:'{0}',", item.CreateDate.ToString()));
        sb.Append(string.Format("Effective:'{0}'", item.EffectiveText));
        sb.Append("}");
    }
    sb.AppendLine("]};");
    string data = sb.ToString();
}
<script type="text/javascript">
    @Html.Raw(data)
    
    var menu = $.ligerMenu({ top: 100, left: 100, width: 120, items:
            [
            { text: '新增', click: newclick },
            { line: true },
            { text: '重置密码', click: modifyclick },
            { line: true },
            { text: '停用\启用', click: stopclick }
            ]
        });
    var grid;
    $(function () {

        grid = $("#maingrid").ligerGrid({
            columns: [
                { display: '用户名', name: 'Name',width:140},
                { display: '创建时间', name: 'CreateDate',width:180},
                { display: '状态', name: 'Effective',width:100}],
                isScroll: false, data: data,pageSize:30,alternatingRow:true,  
                onContextmenu: function (node, e) {
                    actionNodeID = node;
                    menu.show({ top: e.pageY, left: e.pageX });
                    return false;
                }
        }
        );
        resetGridHeight(grid);
            $(window).resize(function () {
                resetGridHeight(grid);
            });
    });   function newclick(item, i) {
        var path = "/Home/UserEdit";
        window.location.href=path;
    }
    function modifyclick(item, i) {
        var path = "/Home/UserReset?id="+actionNodeID.data.ID;
        window.location.href=path;
    }    function stopclick(item, i) {
        var path = "/Home/UserEffective?id="+actionNodeID.data.ID;
        window.location.href=path;
    }
    $(document).ready(function () {
        $("#btnNew").click(function () {
                window.location.href = "/Home/UserEdit";
            }
        );
        $("#btnModify").click(function () {
                var row = grid.getSelectedRow();
                if(row != null)
                {
                    var path = "/Home/UserReset?id="+row.ID;
                    window.location.href=path;
                }
            }
        );

        $("#btnStop").click(function () {
                var row = grid.getSelectedRow();
                if(row != null)
                {
                    var path = "/Home/UserEffective?id="+row.ID;
                    window.location.href=path;
                }
            }
        );
    });
</script>

 <div id="maingrid"></div>